var systemLanguage = navigator.language || navigator.userLanguage;
var countdownSeconds = 60; // 设置倒计时时间（秒）
var countdownTimer;
        // 判断是否是中文
        var isChinese = systemLanguage.toLowerCase().indexOf('zh') !== -1;
        var lang_val=1;//默认是英文
        if (isChinese) {
            lang_val=0
            $(".logoff").text('注销')
            $(".email").attr('placeholder', '请输入邮箱'); 		
            $(".identifyingCode").attr('placeholder', '请输入验证码');
            $(".sendCodeButton").text('发送验证码')
            $(".btn").val('注销')
            $(".des").html('注销步骤：</br>1.输入邮箱</br>2.发送验证码并填写</br>3.点击注销</br>注意：此操作会删除您的账号及其所有数据</br>')
            console.log("当前系统语言是中文");
        } else {
            lang_val=1
            $(".logoff").text('Delete your account')
            $(".email").attr('placeholder', 'email');
            $(".identifyingCode").attr('placeholder', 'verification code'); 
            $(".sendCodeButton").text('Send verification code')
            $(".btn").val('LogOff')
            $(".des").html('Logout procedure: </br>1. Enter the email address </br>2. Send the verification code and enter </br>3. Click Logout </br> Note: This action will delete your account and all of its data </br>')
            console.log("当前系统语言不是中文");
        }
        //获取用户输入的用户名和密码，验证是否正确
        function sendVerificationCode(num) {
                var email_val = $(".email")[num].value
                // 检查是否正在倒计时
                if (!countdownTimer) {
                    if (!email_val) {
                     return lang_val == 1 ? alert('Please enter email') : alert('请输入邮箱');
                    }
                    if(!(/@/.test(email_val))) {
                        return lang_val == 1 ? alert('Please enter the correct email address') : alert('请输入正确的邮箱');
                    }
                    // 禁用发送按钮
                    $(".sendCodeButton").prop("disabled", true);
                    // 发起倒计时
                    countdownTimer = setInterval(function() {
                    countdownSeconds--;
                    // 更新倒计时显示
                    $(".sendCodeButton").text(countdownSeconds + ' s');
                    // 倒计时结束时恢复发送按钮
                    if (countdownSeconds <= 0) {
                        clearInterval(countdownTimer);
                        lang_val == 1 ?$(".sendCodeButton").text('Send verification code'):$(".sendCodeButton").text('发送验证码')
                        $(".sendCodeButton").prop("disabled", false);
                        countdownSeconds = 60; // 重置倒计时时间
                        countdownTimer = null; // 重置倒计时器状态
                    }
                    }, 1000);
                    // 发起请求
                    $.get("https://interface.dhhome-e.com/dh/system/user/code/" + email_val, { lang: lang_val })
                    .done(function(result) {
                        // 请求成功的处理
                        if (result.code == 200) lang_val == 1 ? alert('Verification code sent!') : alert('验证码已发送！');
                        else alert(result.msg)
                    })
                    .fail(function(xhr, status, error) {
                        // 请求失败的处理
                        lang_val==1?alert("There's been a network error"):alert('网络出小差咯')
                    });
                } else {
                    // 如果正在倒计时，给出提示或其他操作
                    lang_val == 1 ? alert('Please wait patiently and check your email in time!') : alert('请耐心等待并及时查看邮件！');
                }
        }
        function logOff(num){
            var email_val = $(".email")[num].value
            var identifyingCode_val = $(".identifyingCode")[num].value
            if (!email_val) {
                return lang_val==1?alert('Please enter email'):alert('请输入邮箱')
            }
            if (!identifyingCode_val) {
                return lang_val==1?alert('Please enter the verification code'):alert('请输入验证码')
            }
            $.ajax({
                type: "POST",
                url: "https://interface.dhhome-e.com/dh/mobile/remove",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    email: email_val,
                    identifyingCode: identifyingCode_val,
                    lang:lang_val,
                }),
                dataType: "json",
                success: function(result) {
                    if(result.code==200)lang_val==1?alert("Logout successful!"):alert('注销成功！')
                    if(result.code==500)lang_val==1?alert("Logout failed!"):alert('注销失败！')
                },
                error: function(xhr, status, error) {
                    lang_val==1?alert("There's been a network error"):alert('网络出小差咯')
                }
            });

        }